const express=require('express')
const pool=require('../pool')
const router=express.Router()
module.exports=router
// 商品列表
router.get('/list',(req,res,next)=>{
    let {pno,pagenum} = req.query
    pagenum = pagenum ? pagenum*1:10
    const start=(pno-1)*pagenum
    pool.query('SELECT pro_id,title,price,auction_pref,author,details FROM su_product LIMIT ?,?',[start,pagenum],(err,result)=>{
        if(err){
            next(err)
            return
        }
        res.send({code:200,message:'操作成功',data:result})
    })
})
// 商品详情
router.get('/details/:pid',(req,res,next) => {
    let {pid} = req.params
    pool.query('SELECT * FROM su_product where pid=?',[pid],(err,result)=>{
        if(err){
            next(err)
            return
        }
        res.send({code:200,statusCode:'OK',data:result[0]})
    })
})
// 类别搜索
router.get('/family/:fid',(req,res,next)=> {
    pool.query('SELECT * FROM su_product WHERE family_id=?',[req.params.fid],(err,result)=>{
        if(err){
            next(err)
            return
        }
        res.send({code:200,statusCode:'OK',list:result})
    })
})